from collections import OrderedDict

from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response


class GatheringPageNumberClass(PageNumberPagination):
    '''定义分页类'''
    page_size = 10
    # 指定获取分页数据时指定`页容量`的参数名称
    page_size_query_param = 'pagesize'
    # 指定分页最大页容量
    max_page_size = 20

    def get_paginated_response(self, data):

        return Response(OrderedDict([
            ('count', self.page.paginator.count),
            ('next', self.get_next_link()),
            ('previous', self.get_previous_link()),
            ('results', data)
        ]))